package fr.umlv.m2.jee.spij.service.ldap.authentification;

import fr.umlv.m2.jee.spij.ldap.actors.Actor;
import org.springframework.stereotype.Component;

import java.io.Serializable;

/**
 * Display an actor. DTO pattern.
 *
 * @author lounes
 */
@Component("actorBean")
public class DisplayActor implements Serializable {

    /**
     * first name of actor.
     */
    private String firstName;

    /**
     * last name of actor.
     */
    private String lastName;

    /**
     * mail of actor.
     */
    private String mail;

    /**
     * login of actor.
     */
    private String login;

    /**
     * pass word of actor.
     */
    private String passWord;

    /**
     * type of actor.
     */
    private String type;

    /**
     * pass word of actor.
     */
    private String menu;

    /**
     * isStudent type of actor.
     */
    private boolean isStudent = false;

    /**
     * isTeacher type of actor.
     */
    private boolean isTeacher = false;

    /**
     * isAdministrative type of actor.
     */
    private boolean isAdministrative = false;

    /**
     * isAdministrator type of actor.
     */
    private boolean isAdministrator = false;

    /**
     * Empty constructor.
     */
    public DisplayActor() {

    }

    /**
     * Constructs a DTO actor from actor.
     *
     * @param actor an actor.
     */
    public DisplayActor(final Actor actor) {
        if (actor != null) {
            storeData(actor);
        }
    }

    /**
     * Stores datas from actor into DisplayActor.
     *
     * @param actor the actor that into display
     */
    private void storeData(final Actor actor) {
        if (actor != null) { // never happen
            if (actor.getFirstName() != null) {
                setFirstName(actor.getFirstName());
            }

            if (actor.getLastName() != null) {
                setLastName(actor.getLastName());
            }

            if (actor.getMail() != null) {
                setMail(actor.getMail());
            }
            if (actor.getLogin() != null) {
                setLogin(actor.getLogin());
            }

            if (actor.getPassWord() != null) {
                setPassWord(actor.getPassWord());
            }

            if (actor.getType() != null) {
                setType(actor.getType());
            }
            if (actor.getMenu() != null) {
                setMenu(actor.getMenu());
            }
            if (actor.getType().equals("Student")) {
                setStudent(true);
            }
            if (actor.getType().equals("Teacher")) {
                setTeacher(true);
            }
            if (actor.getType().equals("Administrative")) {
                setAdministrative(true);
            }
            if (actor.getType().equals("Administrator")) {
                setAdministrator(true);
            }
        }
    }

    /**
     * @param newFirstName the firstName to set.
     */
    public final void setFirstName(final String newFirstName) {
        this.firstName = newFirstName;
    }

    /**
     * @return the first name of Actor.
     */
    public final String getFirstName() {
        return firstName;
    }

    /**
     * @param newLastName the lastName to set.
     */
    public final void setLastName(final String newLastName) {
        this.lastName = newLastName;
    }

    /**
     * @return the last name of actor.
     */
    public final String getLastName() {
        return lastName;
    }

    /**
     * @param newMail the mail to set.
     */
    public final void setMail(final String newMail) {
        this.mail = newMail;
    }

    /**
     * @return the mail of actor.
     */
    public final String getMail() {
        return mail;
    }

    /**
     * @param newLogin the login to set.
     */
    public final void setLogin(final String newLogin) {
        this.login = newLogin;
    }

    /**
     * @return the login of actor.
     */
    public final String getLogin() {
        return login;
    }

    /**
     * @param newPassWord the pass word to set.
     */
    public final void setPassWord(final String newPassWord) {
        this.passWord = newPassWord;
    }

    /**
     * @return the pass word of actor.
     */
    public final String getPassWord() {
        return passWord;
    }

    /**
     * @param newType the type of actor to set.
     */
    public final void setType(final String newType) {
        this.type = newType;
    }

    /**
     * @return the type of actor.
     */
    public final String getType() {
        return type;
    }

    /**
     * @param newMenu the link of actor menu to set.
     */
    public final void setMenu(final String newMenu) {
        this.menu = newMenu;
    }

    /**
     * @return the link of actor menu.
     */
    public final String getMenu() {
        return menu;
    }

    /**
     * @param newIsStudent the boolean isStudent to set.
     */
    public final void setStudent(final boolean newIsStudent) {
        this.isStudent = newIsStudent;
    }

    /**
     * @return the boolean isStudent.
     */
    public final boolean isStudent() {
        return isStudent;
    }

    /**
     * @param newIsTeacher the boolean isTeacher to set.
     */
    public final void setTeacher(final boolean newIsTeacher) {
        this.isTeacher = newIsTeacher;
    }

    /**
     * @return the boolean isTeacher.
     */
    public final boolean isTeacher() {
        return isTeacher;
    }

    /**
     * @param newIsAdministrative the boolean isAdministrative to set
     */
    public final void setAdministrative(final boolean newIsAdministrative) {
        this.isAdministrative = newIsAdministrative;
    }

    /**
     * @return the boolean isAdministrative
     */
    public final boolean isAdministrative() {
        return isAdministrative;
    }

    /**
     * @param newIsAdministrator the boolean isAdministrator to set.
     */
    public final void setAdministrator(final boolean newIsAdministrator) {
        this.isAdministrator = newIsAdministrator;
    }

    /**
     * @return the boolean isAdministrator.
     */
    public final boolean isAdministrator() {
        return isAdministrator;
    }

    /**
     * @return the actor login.
     */
    @Override
    public final String toString() {
        return login;
    }
}
